package com.hy.formula.entity;

import java.io.Serializable;

import com.hy.formula.common.Symbol;

/**
 * 符号项
 * @author huangy
 * @date 2015年4月15日
 */
public class Token implements Serializable {

	private static final long serialVersionUID = 1L;
	
	/**
	 * 符号类型
	 */
	private Symbol symbol;
	/**
	 * 值
	 */
	private String value;
	
	public Token(){
		super();
	}

	public Token(Symbol symbol, String value) {
		super();
		this.symbol = symbol;
		this.value = value;
	}

	public Symbol getSymbol() {
		return symbol;
	}

	public void setSymbol(Symbol symbol) {
		this.symbol = symbol;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	@Override
	public String toString() {
		return "Token [symbol=" + symbol + ", value=" + value + "]";
	}
	
	@Override
	public boolean equals(Object obj) {
		if(obj == null){
			return false;
		}
		Token token = (Token) obj;
		return (token.getValue() == null
				&& this.getValue() == null)
				|| token.getValue().equals(this.getValue())
				&& token.getSymbol().equals(this.getSymbol());
	}
	
	@Override
	public int hashCode() {
		if(this.value == null){
			return this.getSymbol().hashCode()+1;
		}else{
			return this.getSymbol().hashCode()+this.getValue().hashCode();
		}
	}
	
}
